package cn.imvc.app.controllers.seller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.controllers.goods.GoodsControllerImpl;
import cn.imvc.app.entities.Seller;
import cn.imvc.app.entities.User;
import cn.imvc.app.entities.UserSeller;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.app.models.SellerModel;
import cn.imvc.app.models.UserModel;
import cn.imvc.app.models.UserSellerModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;
/**
 * 
 * @author zhanghy
 * @date 2016年8月16日下午3:29:31
 *
 */
public class UserSellerControllerImpl implements UserSellerController{
	static Logger logger = Logger.getLogger(UserSellerControllerImpl.class);
	public Page<Object[]> page;
	public ViewRequest viewRequest;
	public UserSeller userSeller;
	public Seller seller;
	public String search_content;
	public int id;
	public int[] ids;
	public int sellerId;
	public User user;
	public Integer userId;
	
	@Autowired
	UserSellerModel userSellerModel;
	@Autowired
	SellerModel sellerModel;
	@Autowired
	UserModel userModel;
	@Autowired
	LoggingModel loggingModel;
	public String search() {
		return null;
	}

	public String index() {
		if(viewRequest==null){
			viewRequest = new ViewRequest();
		}
		page = userSellerModel.findObjectPage(sellerId,viewRequest);
		return "user-seller/index";
	}

	public String show() {
		userSellerModel.get(id);
		return "user-seller/show";
	}

	public String editNew() {
		seller = sellerModel.get(sellerId);
		return "user-seller/edit";
	}

	public String create() {
		userSeller.setSeller(sellerModel.get(sellerId));
		userSeller.setUserId(user.getId());
		userSellerModel.save(userSeller);
		loggingModel.info(logger,"添加商家用户："+userSeller.getSeller());
		return Render.json(new DialogBean("200","添加成功","user_seller","closeCurrent"));
	}

	public String edit() {
		userSeller = userSellerModel.get(id);
		seller = userSeller.getSeller();
		userId = userSeller.getUserId();
		return "user-seller/edit";
	}

	public String update() {
		userSeller.setSeller(sellerModel.get(sellerId));
		userSeller.setUserId(user.getId());
		userSellerModel.update(id,userSeller);
		loggingModel.info(logger,"修改商家用户："+userSeller.getSeller());
		return Render.json(new DialogBean("200","修改成功","user_seller","closeCurrent"));
	}

	public String destroy() {
		userSellerModel.delete(id);
		loggingModel.info(logger,"删除商家用户："+id);
		return Render.json(new DialogBean("200","删除成功","user_seller"));
	}

	public String destroyBatch() {
		userSellerModel.deleteBatch(ids);
		return Render.json(new DialogBean("200","删除成功","user_seller"));
	}
  
	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public UserSeller getUserSeller() {
		return userSeller;
	}

	public void setUserSeller(UserSeller userSeller) {
		this.userSeller = userSeller;
	}

	public Seller getSeller() {
		return seller;
	}

	public void setSeller(Seller seller) {
		this.seller = seller;
	}

	public String getSearch_content() {
		return search_content;
	}

	public void setSearch_content(String search_content) {
		this.search_content = search_content;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public int getSellerId() {
		return sellerId;
	}

	public void setSellerId(int sellerId) {
		this.sellerId = sellerId;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Page<Object[]> getPage() {
		return page;
	}

	public void setPage(Page<Object[]> page) {
		this.page = page;
	}


}
